package com.shiguiwu.springmybatis.designpattern.facade.controller;

//import com.shiguiwu.facade.starter.door.anntation.DoDoor;
import com.shiguiwu.springmybatis.app.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 门面controller
 * @author: stone
 * @date: Created by 2021/8/29 16:31
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.designpattern.facade.controller
 */
@RestController
@RequestMapping("api/facade")
public class FacadeController {


    @GetMapping("/userInfo")
    public User queryUserInfo(@RequestParam String userId) {
        User user = new User();
        user.setId(1);
        user.setUsername(userId);

        return user;
    }


    /**
     * 添加白名单,一坨坨代码
     * @param userId
     * @return
     */
    @GetMapping("/userInfo1")
    public User queryUserInfo1(@RequestParam String userId) {
        User user = new User();
        user.setId(1);
        user.setUsername(userId);

        List<String> userStringList = new ArrayList<>();
        userStringList.add("1111");
        userStringList.add("aaaa");
        userStringList.add("bbbb");
        if (!userStringList.contains(userId)) {
            user.setUsername("非白名单，禁止请求。。。。。。");
            return user;
        }
        return user;
    }


    /**
     * 用门面模式修改，和业务代码相分离
     * @param userId
     * @return
     */
//    @DoDoor(key = "userId",returnJson = "{\n" +
//            "  \"id\": 1,\n" +
//            "  \"username\": \"非白名单，禁止请求。。。。。。\"\n" +
//            "}")
    @GetMapping("/userInfoPlus")
    public User userInfoPlus(@RequestParam String userId) {
        User user = new User();
        user.setId(1);
        user.setUsername(userId);

        //List<String> userStringList = new ArrayList<>();
        //userStringList.add("1111");
        //userStringList.add("aaaa");
        //userStringList.add("bbbb");
        //if (!userStringList.contains(userId)) {
        //    user.setUsername("非白名单，禁止请求。。。。。。");
        //    return user;
        //}
        return user;
    }
}
